package com.rc.web.controller;

import com.mybatisflex.core.paginate.Page;
import com.rc.common.annotate.WithoutTenant;
import com.rc.pojo.dto.ill.IllAddDTO;
import com.rc.pojo.dto.ill.IllPageQuery;
import com.rc.pojo.dto.ill.IllUpdateDTO;
import com.rc.pojo.vo.ill.IllCommonVO;
import com.rc.pojo.vo.ill.IllDetailVO;
import com.rc.pojo.vo.ill.IllPageVO;
import com.rc.pojo.vo.ill.IllVO;
import com.rc.web.service.IllService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 活动表 控制层。
 *
 * @author sym
 * @since 2024-05-26
 */
@RestController
@RequestMapping("/ill")
@Api(tags = "病虫害")
@RequiredArgsConstructor
@Validated
public class IllController {
    private final IllService illService;

    @PostMapping
    @ApiOperation("新增病虫害")
    public void add(@RequestBody @Validated IllAddDTO dto) {
        illService.add(dto);
    }

    @PutMapping
    @ApiOperation("修改活动")
    public void updateOneById(@RequestBody @Validated IllUpdateDTO dto) throws InterruptedException {
        illService.updateOneById(dto);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除活动")
    public void deleteOneById(@PathVariable Long id) {
        illService.deleteOneById(id);
    }

    @GetMapping("/list")
    public List<IllVO> getList(){
        return illService.getList();
    }

    @GetMapping("/commonIll")
    @ApiOperation("获取该植物常见病虫害")
    @WithoutTenant
    public IllCommonVO getCommonIll(@NotNull @RequestParam Long plantId){
        return illService.getCommonIll(plantId);
    }

    @GetMapping("/detail/{id}")
    @ApiOperation("获取病虫害详情")
    public IllDetailVO getDetail(@PathVariable Long id){
        return illService.getDetail(id);
    }

    @GetMapping("/{id}")
    public IllVO getByOneId(@PathVariable @NotNull Long id){
        return illService.getOneById(id);
    }


    @GetMapping("/page")
    @ApiOperation("分页病虫害")
    public Page<IllPageVO>  getPage(IllPageQuery dto){
        return illService.getPage(dto);
    }
}
